package com.network.topo.conf;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import com.network.topo.TopoDiscoverMain;
import com.network.topo.dao.TopoDaoAbstract;


public class SNMPConf {

	private static SNMPConf snmpConf = null;

	

	public static SNMPConf getInstance() {
		if (snmpConf == null) {
			synchronized(SNMPConf.class) {
				if (snmpConf == null) {
					try{
						snmpConf = SystemConfOnLoad.getSNMPConf();
					}catch(Exception ex){
						
					}
				}
				if (snmpConf == null) {
					snmpConf = new SNMPConf();
					snmpConf.init();
				}
			}
		}
		return snmpConf;
	}

	private  void init(){
		String sql = "select * from snmp_conf ";
		ResultSet res = null;
		try
		{
			res = TopoDiscoverMain.dboper.executeQuery(sql, null);
			if (res.next())
			{
				
				String ipAndNet = res.getString("ipAndNetmask");
				if( ipAndNet != null ){
					String [] ipAndNets = ipAndNet.split(",");
					ipAndNetmask= Arrays.asList(ipAndNets);
				}
				String seedIpAddrDb = res.getString("seedIpAddr");
				if( seedIpAddrDb != null ){
					String [] seedIpAddrDbs = seedIpAddrDb.split(",");
					seedIpAddr= Arrays.asList(seedIpAddrDbs);
				}
				String vlanDb = res.getString("vlan");
				if( vlanDb != null ){
					String [] vlanDbs = vlanDb.split(",");
					vlan= Arrays.asList(vlanDbs);
				}
				String readCommDb = res.getString("readComm");
				if( readCommDb != null ){
					String [] readCommDbs = readCommDb.split(",");
					readComm= Arrays.asList(readCommDbs);
				}
				String writeCommDb = res.getString("writeComm");
				if( writeCommDb != null ){
					String [] writeCommDbs = writeCommDb.split(",");
					writeComm= Arrays.asList(writeCommDbs);
				}

				isOnlyArp = res.getInt("isOnlyArp")==1?true:false;
				
				isAutoVlan =res.getInt("isAutoVlan")==1?true:false;
			}

		}
		catch (SQLException e)
		{
			e.printStackTrace();
		}
		finally
		{
			TopoDaoAbstract.dealRes(res);
		}
	}
	
	public List<String> readComm;
	public List<String> writeComm;

	private List<String> ipAndNetmask = new ArrayList<String>();

	private List<String> seedIpAddr = new ArrayList<String>();
	
	private List<String> vlan = new ArrayList<String>();

	private boolean isOnlyArp = true;
	
	private boolean isAutoVlan = false;

	public boolean isOnlyArp() {
		return isOnlyArp;
	}

	public void setIsOnlyArp(boolean isOnlyArp) {
		this.isOnlyArp = isOnlyArp;
	}

	public boolean isAutoVlan() {
		return isAutoVlan;
	}

	public void setIsAutoVlan(boolean isAutoVlan) {
		this.isAutoVlan = isAutoVlan;
	}

	public List<String> getVlan() {
		return vlan;
	}

	public void setVlan(List<String> vlan) {
		this.vlan = vlan;
	}

	public  List<String> getSeedIpAddr() {
		return seedIpAddr;
	}

	public void setSeedIpAddr( List<String> seedIpAddr) {
		this.seedIpAddr = seedIpAddr;
	}

	public void setIpAndNetmask(List<String> ipAndNetmask) {
		this.ipAndNetmask = ipAndNetmask;
	}

	
	public List<String> getRead_community() {

		return readComm;
	}

	public List<String> getReadComm() {
		return readComm;
	}

	public void setReadComm(List<String> readComm) {
		this.readComm = readComm;
	}

	public List<String> getWriteComm() {
		return writeComm;
	}

	public void setWriteComm(List<String> writeComm) {
		this.writeComm = writeComm;
	}

	public List<String> getIpAndNetmask() {
		if( ipAndNetmask == null ){
			ipAndNetmask = new ArrayList<String>();
		}
		return ipAndNetmask;
	}
}
